<?php
if(isset($this->header) && $this->header){
    $this->headTitle($this->header,'append');
}else{
    $this->headTitle('Rao vặt','append');
}    
//pr($this->proNewest);
?>
<div class="col-md-9">
    <div class="mycontent">    
        <div class="navi"> 
            <?php echo $this->navi?>
        </div>
        
        <div class="adsearch">
            <?php echo $this->form?>
        </div><!-- end adsearch -->
        
        <div class="adnewest">
            <div class="slider-wrapper">
                <div id="slider">
                <?php
                    $i=1;                         
                    foreach($this->proNewest as $pro){
                ?>
                        <div class="<?php echo 'slide'+$i++ ?>">
                            <a href="<?=$this->url(array('module'=>'default', 'controller'=>'product', 'action'=>'detail', 'id'=>$pro['id'],'title'=>$pro['shortTitle']),'product.detail',true);?>" class="title" title=""><?php echo $pro['title'] ?></a>
                            <p class="content">Đăng bởi <span class="owner"><?php echo $pro['mobile'] ?></span> lúc <time><?php echo date('d/m/Y H:i:s',$pro['startDate']) ?></time></p>                            
                        </div>
                <?php
                    }
                ?>
                </div>
                <div id="slider-control-nav"></div>
            </div>
        </div><!-- end adsearch -->
        
        <!--<div class="advertise" style="margin-bottom:10px;text-align:center;">
            <div style="width:835px;height:80px;background-color:#bababa;margin: 0 auto;text-align:center;padding:10px;">
                <label style="font-size:20px;color:red;">Dành cho quảng cáo 835 x 80</label>
                <br />
                <label style="font-size:20px;color:red;">Liên hệ: 0166 555 4486</label>
            </div>
        </div><!-- end advertise -->
    
        <div class="mylist">
            <?php
                if($_COOKIE['all']==0&&$_COOKIE['pe']==0&&$_COOKIE['co']==0){
                    $cook['all'] = 0;$cook['pe'] = 1;$cook['co'] = 1;
                }else{
                    $cook['all']=$_COOKIE['all'];$cook['pe']=$_COOKIE['pe'];$cook['co']=$_COOKIE['co'];
                }
            ?>
            <div role="tabpanel">
            <!-- Nav tabs -->
                <ul class="nav nav-tabs" role="tablist">
                    <li role="presentation" <?php if($cook['all']=='0')echo 'class="active"';?>>
                        <a href="#all" aria-controls="all" role="tab" data-toggle="tab">Tất cả | (<?php echo $this->total;?>)</a>
                    </li>
                    <li role="presentation" <?php if($cook['pe']=='0')echo 'class="active"';?>>
                        <a href="#pe" aria-controls="pe" role="tab" data-toggle="tab">Cá nhân | (<?php echo $this->totalPerson;?>)</a>
                    </li>
                    <li role="presentation" <?php if($cook['co']=='0')echo 'class="active"';?>>
                        <a href="#co" aria-controls="co" role="tab" data-toggle="tab">Công Ty | (<?php echo $this->totalCompany;?>)</a>
                    </li>  
                    
                    <!--<li style="float: right;">
                        <div class="btn-group" role="group" aria-label="...">
                            <button type="button" class="btn btn-default"><span style="color: #ff9900" class="glyphicon glyphicon-th-list"></span></button>                                
                            <button type="button" class="btn btn-default"><span style="color: #ff9900" class="glyphicon glyphicon-align-justify"></span></button>
                        </div>
                    </li>-->   
                    
                    <li style="float:right;margin-right:5px;">
                        <div class="btn-group" role="group" aria-label="...">
                            <button id="sortView" title="Sắp xếp tin theo lượt xem" style="color:#48649f;font-weight:bold;" type="button" class="btn btn-default"><span class="glyphicon glyphicon-eye-open"></span></button>
                            <button id="sortDate" title="Sắp xếp tin ngày đăng" style="color:#48649f;font-weight:bold;" type="button" class="btn btn-default"><span class="glyphicon glyphicon-calendar"></span></button>
                        </div>
                    </li>
               
                </ul>
                <!-- Tab panes -->
                <div class="tab-content">
                    <div role="tabpanel" id="all" <?php echo ($cook['all']==0)?'class="tab-pane active"':'class="tab-pane"';?>>
                        <div class="list-product">
                            <?php
                                if($this->proAll){
                                foreach($this->proAll as $pro){
                                    $pro['photo'] = json_decode($pro['photo']);
                                    $today = new DateTime(date('Y-m-d H:i', time() ));
                                    $startDate = new DateTime(date('Y-m-d H:i',$pro['startDate']));
                                    if($pro['type']=='no'){
                                        $start = new DateTime(date('Y-m-d H:i',$pro['startDate']));
                                        $now = new DateTime(date('Y-m-d H:i', time() ));
                                        if($now->diff($start)->d>0)
                                            $deltaTime = $now->diff($start)->d.' ngày trước';
                                        elseif($now->diff($start)->h>0)
                                            $deltaTime = $now->diff($start)->h.' giờ trước';
                                        else
                                            $deltaTime = $now->diff($start)->i.' phút trước';
                                    }
                            ?>
                                    <div class="bs-callout bs-callout-product <?php echo ($pro['type']=='vi')?'vipstyle':'nostyle';?>" <?php echo ($pro['type']=='vi')?'style="border-color:#2980B9"':'';?>>
                                        <a data="<?php echo $pro['id'];?>" href="<?=$this->url(array('module'=>'default', 'controller'=>'product', 'action'=>'detail', 'id'=>$pro['id'],'title'=>$pro['shortTitle']),'product.detail',true);?>" title="<?php echo $pro['title']?>"><img src="<?php echo $pro['photo'][0]?>" class="img-polaroid" onerror="this.onerror=null;this.src='public/static/images/noimage.jpg';"/></a>
                                        <p class="view" style="float: right;"><?php echo number_format($pro['view'],0,'.',',')?> lượt xem <span <?php echo ($pro['type']=='no')?'style="display:none"':''?> class="vip_product"><img src="public/static/images/vip.png" title="Tin VIP"/></span></p>
                                        <a data="<?php echo $pro['id'];?>" href="<?=$this->url(array('module'=>'default', 'controller'=>'product', 'action'=>'detail', 'id'=>$pro['id'],'title'=>$pro['shortTitle']),'product.detail',true);?>" title="<?php echo $pro['title']?>">
                                            <h5><?php echo $pro['title']?></h5>
                                        </a>
                                        <p class="price"><strong>Giá:&nbsp;<?php echo number_format($pro['price'],0,'.',',')?> VNĐ</strong></p>
                                        <div class="col-md-4">
                                            <p class="catalog"><?php echo $pro['itemName']?></p>
                                        </div> 
                                        <div class="col-md-3">
                                            <p class="area"><?php echo ($pro['human']=='co')?'(Công ty) ở':''?>&nbsp;<?php echo $pro['areaName']?></p>
                                        </div>
                                        <div class="col-md-3" style="float: right;">
                                            <time>
                                                <?php echo ($pro['type']=='vi')?date('d-m-Y',$pro['startDate']):$deltaTime?>&nbsp;
                                                <?php echo ($today->diff($startDate)->d<2)?'<span class="new_product"><img src="public/static/images/new.png" title="Tin mới"/></span>':'' ?>
                                            </time>
                                        </div>
                                    
                                    </div>
                            <?php
                                }}
                                else{
                                    echo 'Không có dữ liệu';
                                }
                            ?>                                                                                                          
                        </div>
                        <nav class="maket">
                             <div class="pagination">                                                                                                   
                                <?php    
                                    //pr($this);                             
                                    if($this->paginator){
                                        echo $this->paginationControl($this->paginator,'Sliding' , 'index/pagination.phtml',
                                        $this->params); 
                                    }
                                ?>
                            </div>
                        </nav>
                    
                    </div>
                    <div role="tabpanel" id="pe" <?php echo ($cook['pe']==0)?'class="tab-pane active"':'class="tab-pane"';?>>                    
                        <div class="list-product">
                            <?php
                            if($this->proPerson){
                                foreach($this->proPerson as $pro){
                                    $pro['photo'] = json_decode($pro['photo']);
                                    $today = new DateTime(date('Y-m-d H:i', time() ));
                                    if($pro['type']=='no'){
                                        $start = new DateTime(date('Y-m-d H:i',$pro['startDate']));                                    
                                        $now = new DateTime(date('Y-m-d H:i', time() ));                                        
                                        if($now->diff($start)->d>0)                                        
                                            $deltaTime = $now->diff($start)->d.' ngày trước';
                                        elseif($now->diff($start)->h>0)
                                            $deltaTime = $now->diff($start)->h.' giờ trước';
                                        else
                                            $deltaTime = $now->diff($start)->i.' phút trước';                                        
                                    }                                                                        
                            ?>                            
                                    <div class="bs-callout bs-callout-product <?php echo ($pro['type']=='vi')?'vipstyle':'nostyle';?>" <?php echo ($pro['type']=='vi')?'style="border-color:#2980B9"':'';?>>
                                        <a data="<?php echo $pro['id'];?>" href="<?=$this->url(array('module'=>'default', 'controller'=>'product', 'action'=>'detail','id'=>$pro['id'],'title'=>$pro['shortTitle']),'product.detail',true)?>" title="<?php echo $pro['title']?>"><img src="<?php echo $pro['photo'][0]?>" class="img-polaroid" onerror="this.onerror=null;this.src='public/static/images/noimage.jpg';"/></a>
                                        <p class="view" style="float: right;"><?php echo number_format($pro['view'],0,'.',',')?> lượt xem <span <?php echo ($pro['type']=='no')?'style="display:none"':''?> class="vip_product"><img src="public/static/images/vip.png" title="Tin VIP"/></span></p>                                            
                                        <a data="<?php echo $pro['id'];?>" href="<?=$this->url(array('module'=>'default', 'controller'=>'product', 'action'=>'detail','id'=>$pro['id'],'title'=>$pro['shortTitle']),'product.detail',true)?>" title="<?php echo $pro['title']?>">
                                            <h5><?php echo $pro['title']?></h5>
                                        </a>
                                        <p class="price"><strong>Giá:&nbsp;<?php echo number_format($pro['price'],0,'.',',')?> VNĐ</strong></p>                                        
                                        <div class="col-md-4">
                                            <p class="catalog"><?php echo $pro['itemName']?></p>
                                        </div> 
                                        <div class="col-md-3">
                                            <p class="area"><?php echo ($pro['human']=='co')?'(Công ty) ở':''?>&nbsp;<?php echo $pro['areaName']?></p>
                                            
                                        </div>
                                        <div class="col-md-3" style="float: right;">
                                            <time>
                                                <?php echo ($pro['type']=='vi')?date('d-m-Y',$pro['startDate']):$deltaTime?>&nbsp;
                                                <?php echo ($today->diff($startDate)->d<2)?'<span class="new_product"><img src="public/static/images/new.png" title="Tin mới"/></span>':'' ?>
                                            </time>
                                        </div>
                                                                                                                     
                                    </div>
                            <?php
                                }}
                                else{
                                    echo 'Không có dữ liệu';
                                }
                            ?>                                                                                                          
                        </div>
                        <nav class="maket">
                             <div class="pagination">
                            <?php 
                                if($this->paginatorPe){
                                    echo $this->paginationControl($this->paginatorPe,'Sliding' , 'index/pagination.phtml',$this->params); 
                                }
                            ?>
                            </div>
                        </nav>                                        
                    </div>
                    <div role="tabpanel" id="co" <?php echo ($cook['co']==0)?'class="tab-pane active"':'class="tab-pane"';?>>
                        <div class="list-product">
                            <?php 
                            if($this->proCompany){
                                foreach($this->proCompany as $pro){
                                    $pro['photo'] = json_decode($pro['photo']);
                                    if($pro['type']=='no'){
                                        $start = new DateTime(date('Y-m-d H:i',$pro['startDate']));                                    
                                        $now = new DateTime(date('Y-m-d H:i', time() ));                                        
                                        if($now->diff($start)->d>0)                                        
                                            $deltaTime = $now->diff($start)->d.' ngày trước';
                                        elseif($now->diff($start)->h>0)
                                            $deltaTime = $now->diff($start)->h.' giờ trước';
                                        else
                                            $deltaTime = $now->diff($start)->i.' phút trước';                                        
                                    }                                
                            ?>                            
                                    <div class="bs-callout bs-callout-product <?php echo ($pro['type']=='vi')?'vipstyle':'nostyle';?>" <?php echo ($pro['type']=='vi')?'style="border-color:#2980B9"':'';?>>
                                        <a data="<?php echo $pro['id'];?>" href="<?=$this->url(array('module'=>'default', 'controller'=>'product', 'action'=>'detail', 'id'=>$pro['id'], 'title'=>$pro['shortTitle']),'product.detail',true)?>" title="<?php echo $pro['title']?>"><img src="<?php echo $pro['photo'][0]?>" class="img-polaroid" onerror="this.onerror=null;this.src='public/static/images/noimage.jpg';" alt="<?php echo $pro['shortTitle']?>" /></a>
                                        <p class="view" style="float: right;"><?php echo number_format($pro['view'],0,'.',',')?> lượt xem <span <?php echo ($pro['type']=='no')?'style="display:none"':''?> class="vip_product"><img src="public/static/images/vip.png" title="Tin VIP"/></span></p>                                            
                                        <a data="<?php echo $pro['id'];?>" href="<?=$this->url(array('module'=>'default', 'controller'=>'product', 'action'=>'detail', 'id'=>$pro['id'], 'title'=>$pro['shortTitle']),'product.detail',true)?>" title="<?php echo $pro['title']?>">
                                            <h5><?php echo $pro['title']?></h5>
                                        </a>
                                        <p class="price"><strong>Giá:&nbsp;<?php echo number_format($pro['price'],0,'.',',')?> VNĐ</strong></p>                                        
                                        <div class="col-md-4">
                                            <p class="catalog"><?php echo $pro['itemName']?></p>
                                        </div> 
                                        <div class="col-md-3">
                                            <p class="area"><?php echo ($pro['human']=='co')?'(Công ty) ở':''?>&nbsp;<?php echo $pro['areaName']?></p>
                                            
                                        </div>
                                        <div class="col-md-3" style="float: right;">
                                            <time>
                                                <?php echo ($pro['type']=='vi')?date('d-m-Y',$pro['startDate']):$deltaTime?>&nbsp;
                                                <?php echo ($today->diff($startDate)->d<2)?'<span class="new_product"><img src="public/static/images/new.png" title="Tin mới"/></span>':'' ?>
                                            </time>
                                        </div>
                                                                                                                     
                                    </div>
                            <?php
                                }}
                                else{
                                    echo 'Không có dữ liệu';
                                }
                            ?>                                                                                                          
                        </div>
                        <nav class="maket">
                               <div class="pagination">
                            <?php 
                                if($this->paginatorCo){
                                    echo $this->paginationControl($this->paginatorCo,'Sliding' , 'index/pagination.phtml',$this->params); 
                                }
                            ?>
                            </div>
                        </nav>                       
                    </div>                                
                </div>                        
            </div>                            
        </div>                                        
    </div>
</div>
<script>
$('.bs-callout-product > a').click(function(){
    var id=$(this).attr('data');
    $.ajax({
            type: "get",
            url : "default/index/index/",
            data: {
                proId : id,
                act : 'form'
            },
            success: function(data){
                
            }
        });
});
$( document ).ready(function() {
    $('li[role="presentation"] a').click(function(){        
        var currentLocation = location.protocol + "//" + location.host;
        var checkLoad= <?php echo $this->checkLoad; ?>;
        if(checkLoad==1){            
            window.location.href = currentLocation;
        }
        
        var cook = $(this).attr('aria-controls');                        
        var cookie=getCookie(cook);                
        if(cookie==null){
            setCookie(cook,'1','2000000');            
        }
        else{
            setCookie(cook,'0','2000000');
        } 
        $('li[role=presentation] a').each(function(){            
            var cookother = $(this).attr('aria-controls');            
            var cookieother=getCookie(cookother);
            //alert(cookother);
            if(cook!=cookother)
                setCookie(cookother,'1','2000000');                
        }); 
        
        
    }); 
    <?php
    	if(Zend_Controller_Front::getInstance()->getRequest()->getParam('catId')){
    ?>            
            var id=<?php echo Zend_Controller_Front::getInstance()->getRequest()->getParam('catId') ?>;
            $("a[data="+id+"]").css({'color':'#2980b9','font-weight':'bold',});
            $("a[data="+id+"]").parent().parent().find('ul').removeClass('hidden');
            $("a[data="+id+"]").parent().find('span').removeClass('glyphicon-chevron-right');
            $("a[data="+id+"]").parent().find('span').addClass('glyphicon-chevron-down');
            setCookie('cat_'+id,'1','2000000');                            
    <?php
        }   
    ?>
    <?php
    	if(Zend_Controller_Front::getInstance()->getRequest()->getParam('itemId')){
    ?>
            var id='<?php echo Zend_Controller_Front::getInstance()->getRequest()->getParam('itemId') ?>';
            if($.isNumeric(id)){
                $('.id_'+id).css({'color':'#2980b9','font-weight':'bold'});                
                //$('.id_'+id).parent().parent().parent().parent().toggleClass('active');
                $('.id_'+id).parent().parent().parent().removeClass('hidden');
                $('.id_'+id).parent().parent().parent().parent().find('span > span').removeClass('glyphicon-chevron-right');
                $('.id_'+id).parent().parent().parent().parent().find('span > span').addClass('glyphicon-chevron-down');                                
                var catId =$('.id_'+id).parent().parent().parent().parent().find('span').attr('id');                                        
                setCookie(catId,'1','2000000');   
            }else{
                var idCat = id.split('_');                
                $("a[data="+idCat[1]+"]").css({'color':'#2980b9','font-weight':'bold'});                
                $("a[data="+idCat[1]+"]").parent().parent().find('ul').removeClass('hidden');
                $("a[data="+idCat[1]+"]").parent().find('span').removeClass('glyphicon-chevron-right');
                $("a[data="+idCat[1]+"]").parent().find('span').addClass('glyphicon-chevron-down');                                                                        
                setCookie(id,'1','2000000');
            }                                        
    <?php
        }   
    ?>
                
    <?php        
    	if(Zend_Controller_Front::getInstance()->getRequest()->getParam('view')){
    ?>
            $('button#sortView').css({'backgroundColor':'#2980B9','color':'white'})                                    
    <?php
        }else{
    ?>
            $('button#sortDate').css({'backgroundColor':'#2980B9','color':'white'})
    <?php
        }
    ?>
    
    $('button#sortView').click(function(){        
        if($('input[name=view]').val() == 0){
            $('input[name=view]').val('1'); 
        }else{
            $('input[name=view]').val('0');
        }        
        //alert($('input[name=view]').val());
        $('form#formSearch button').click();                        
    });
    $('button#sortDate').click(function(){
        $('button#sortView').click();
    });
                            
});

</script>  

<script type="text/javascript">
$(document).ready(function() {
    var slider = $('#slider').leanSlider({
        pauseTime: 6000,        
        controlNav: '#slider-control-nav'
    });
});
</script>  